use std::sync::Arc;

use clap::Parser;
use excel2bin::excels::{
    code_generater::TsCodeGenerater,
    export::{export, ExportInfo},
};

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
    /// input directory
    #[arg(short, long)]
    input: String,

    /// output directory
    #[arg(short, long, default_value = "")]
    output: String,

    /// script directory
    #[arg(short, long, default_value = "")]
    script: String,

    #[arg(short, long, default_value = "1")]
    title_idx: String,

    #[arg(short, long, default_value = "2")]
    a_type_idx: String,

    #[arg(short, long, default_value = "3")]
    comment_idx: String,

    #[arg(short, long, default_value = "4")]
    data_idx: String,
}

fn main() {
    let args = Args::parse();
    let input: String = args.input;
    let mut output: String = args.output;
    if output.is_empty() {
        output = input.clone();
    }
    let mut script: String = args.script;
    if script.is_empty() {
        script = output.clone();
    }

    let title_idx = args.title_idx.parse::<u32>().unwrap();
    let type_idx = args.a_type_idx.parse::<u32>().unwrap();
    let comment_idx = args.comment_idx.parse::<u32>().unwrap();
    let data_idx = args.data_idx.parse::<u32>().unwrap();

    println!(
        "input:{} output:{} script:{} type_idx:{} title_idx:{} comment_idx:{} data_idx:{}",
        input, output, script, type_idx, title_idx, comment_idx, data_idx
    );

    let code_generater = Arc::new(TsCodeGenerater {});
    let info = Arc::new(ExportInfo::new(
        input,
        output,
        script,
        type_idx,
        title_idx,
        comment_idx,
        data_idx,
    ));
    export(info, code_generater);
}
